<?php
namespace Home\Controller;
use Think\Controller;
class CustomerController extends CommonController {
	//显示添加表格
    public function add(){
    $this->display();   
    }
    //添加客户
    public function ad(){
		    $data['company']=I('post.mingcheng');
		    $data['name']=I('post.name');
		    $data['telephone']=I('post.phone');
		    $data['fixed']=I('post.guhua');
		    $data['qq']=I('qq');
		    $data['domain']=I('yuming');
		    $data['data']=I('ziliao');
		    $data['date']=date("y-m-d");
		    $data['enddate']=date('Y-m-d',strtotime('+1 year'));
		    $sub=I('post.submit');
		if(empty($sub)){
			
			$d=M('customer');
			$a=$d->data($data)->add();
			if($a){
				$this->success('添加成功！！！');
				
				}
			
			
			}else{
				
		$this->error('没有提交任何内容！！！！','/Home/Customer/add');		
				
				}
		
		
		}
		//客户列表
    public function lists(){
      $User = M('customer'); // 实例化User对象
    $count = $User->count();// 查询满足要求的总记录数
    $Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $Page->setConfig('prev', '上一页');
    $Page->setConfig('next', '下一页');
    $Page->setConfig('theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
    
    $show = $Page->show();// 分页显示输出
    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
    $list = $User->order('date')->limit($Page->firstRow.','.$Page->listRows)->select();
    $this->assign('list',$list);// 赋值数据集
    $this->assign('page',$show);// 赋值分页输出
    $this->display(); // 输出模板
    
    
    }
    //客户详细信息
    public function more(){
		$data['id']=I('get.id');
		$user=M('customer');
		$list=$user->where($data)->find();
		$this->assign('list',$list);
		$this->display();
		
		
		}
	//客户更新信息
      public function uplist(){
		$data['id']=I('get.id');
		$user=M('customer');
		$list=$user->where($data)->find();
		$this->assign('list',$list);
		$this->display();
		
		
		} 
 //客户信息更新
 public function up(){
	  $hidd=I('post.hidd');
	  $sub=I('post.submit');
	 if($hidd){
		    $data['id']=I('post.hidd');
     		$data['company']=I('post.mingcheng');
		    $data['name']=I('post.name');
		    $data['telephone']=I('post.phone');
		    $data['fixed']=I('post.guhua');
		    $data['qq']=I('qq');
		    $data['domain']=I('yuming');
		    $data['data']=I('ziliao');   
		 	$d=M('customer');
			$a=$d->save($data);
			
			if($a){
				$this->success('修改成功！！！');
				
				}
		 }else{
			 
			$this->error('不存在要更新的内容！！！');
			 
			 
			 }
 
	 
	 
	 }
	 public	function del(){
		 
		 $user=M('customer');
		 $data=I('get.id');
		 $user->delete($data);
		 
		 $this->success('删除成功！！！','/Home/Customer/lists/');
		 
		 }
    
}
